package com.bw.service.impl;

import com.bw.domain.Role;
import com.bw.domain.TbMenu;
import com.bw.domain.User;
import com.bw.exception.MyRuntimeException;
import com.bw.mapper.UserMapper;
import com.bw.service.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

/**
 * @Author: zhaijiaqi
 * @Date: 2025/3/12 15:18
 * @Description:
 **/
@Service
public class UserServiceImpl implements UserService {

    @Autowired
    UserMapper userMapper;

    @Override
    public User getlogin(String username) {
        return userMapper.getlogin(username);
    }

    @Override
    public List<Role> getrolelist(Integer id) {
        return userMapper.getrolelist(id);
    }

    @Override
    public User getuser(Integer id) {
        return userMapper.getuser(id);
    }

    @Override
    public List<TbMenu> getmenulist(Integer id) {
        return userMapper.getmenulist(id);
    }

    @Override
    public List<Role> getallrole() {
        return userMapper.getallrole();
    }

    @Override
    public User checkusername(String username) {
        return userMapper.checkusername(username);
    }

    @Transactional(rollbackFor = MyRuntimeException.class)

    @Override
    public boolean add(User user) {

        try {
            userMapper.add(user);
            userMapper.inserusrerrole(user);
            return true;

        }catch (MyRuntimeException e){
            e.printStackTrace();
            throw new MyRuntimeException(e.getMessage());
        }



    }
}
